#include "RsGisLibClassGenStrRandAccPts.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibClassGenStrRandAccPts::RsGisLibClassGenStrRandAccPts(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibClassGenStrRandAccPts();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_InputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_InputFilePath_clicked()));
	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_Execute, SIGNAL(clicked()), this, SLOT(on_action_Button_Execute_clicked()));

	ui->lineEdit_InputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\In");
	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\Out");

	QStringList ForseList;
	ForseList.append("False");
	ForseList.append("True");
	ui->comboBox_Forse->addItems(ForseList);

	ui->lineEdit_ClassColumn->setText("ClassColumn");
	ui->lineEdit_ClassImgVecCol->setText("ClassImgVecCol");
	ui->lineEdit_ClassRefVecCol->setText("ClassRefVecCol");
	ui->lineEdit_NumPts->setText("1");
	ui->lineEdit_Seed->setText("1");
	ui->comboBox_Forse->setCurrentIndex(0);

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibClassGenStrRandAccPts::on_action_Button_InputFilePath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_InputFilePath->setText(str.toUtf8());
}

void RsGisLibClassGenStrRandAccPts::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibClassGenStrRandAccPts::on_action_Button_Execute_clicked()
{
	{
		if (ui->lineEdit_InputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Input File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OutputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Output File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_ClassColumn->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Class Column is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_ClassImgVecCol->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Class Img Vec Col is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_ClassRefVecCol->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Class Ref Vec Col is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_NumPts->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Num Pts is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Seed->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Seeds is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Priority->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Priority is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}
	}

	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("Classification"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("GenStrRandAccPts"));
	AlgParaList << QVariant(QString(ui->lineEdit_InputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_ClassColumn->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_ClassImgVecCol->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_ClassRefVecCol->text()));
	AlgParaList << QVariant(int(ui->lineEdit_NumPts->text().toInt()));
	AlgParaList << QVariant(int(ui->lineEdit_Seed->text().toInt()));
	AlgParaList << QVariant(int(ui->comboBox_Forse->currentIndex()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}